package com.hzit.rocketmq.listener;

import com.hzit.common.utils.SmsUtil;
import lombok.SneakyThrows;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@RocketMQMessageListener(consumerGroup = "consumer-group",topic = "topic-sms")
@Component
public class MySmsListener implements RocketMQListener<Map> {

	@Autowired
	private SmsUtil smsUtil;

	@SneakyThrows
	@Override
	public void onMessage(Map message) {
		System.out.println("message = " + message);
		//1. 获取发来的信息
		String templateParam = message.get("templateParam").toString();
		String phone = message.get("phone").toString();
		String signName = message.get("signName").toString();
		String templateCode = message.get("templateCode").toString();
		String accessKeyId = message.get("accessKeyId").toString();
		String accessKeySecret = message.get("accessKeySecret").toString();
		//2. 向手机发送验证码
		smsUtil.sendSms(accessKeyId,accessKeySecret,phone,signName,templateCode,templateParam);
	}
}
